package com.zhentao.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zhentao.domain.SysUser;
import com.zhentao.domain.vo.Result;
import com.zhentao.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: SysUserController
 * @Desrciption: Mr.chengfenzhan
 * @Author: 知安_程烽展
 * @Date: 2024/8/22 8:30
 */
@RestController
@RequestMapping("/sysuser")
@Tag(name = "用户管理")
public class SysUserController {
    @Autowired
    private SysUserService service;

    /**
     * 登录方法，根据手机号验证码登录
     * @param phone
     * @param code
     * @return
     */
    @PostMapping("/login")
    @Operation(summary = "登录")
    public Result login(String phone , String code)
    {
        return service.login(phone , code);
    }

    /**
     * 生成验证码
     * @param phone
     * @return
     */
    @GetMapping("/getCode")
    @Operation(summary = "获取验证码")
    public Result getCode(String phone){
        return service.getCode(phone);
    }

    /*
    * 实名认证
    * */
    @PostMapping("/realName")
    @Operation(summary = "实名认证")
    public Result realName(SysUser sysUser){
        return service.realName(sysUser);
    }
//    判断押金是否为空 0为未缴纳 大于0为已缴纳
    @PostMapping("/isDeposit")
    @Operation(summary = "判断押金是否为空")
    public Result isDeposit(SysUser user){
//        查询用户信息
        SysUser sysUser = service.getUserInfo(user.getUid());
//        判断押金是否为 0未缴纳  大于0已缴纳
        return service.isDeposit(sysUser);
    }
//    添加押金
    @PostMapping("/addDeposit")
    @Operation(summary = "添加押金")
    public Result addDeposit(SysUser sysUser){
        return service.addDeposit(sysUser);
    }
    @GetMapping("/userInfo")
    @Operation(summary = "获取用户信息")
    public Result userInfo(){
        SysUser userInfo = service.getUserInfo();
        return BeanUtil.isEmpty(userInfo)?Result.build(null,400,"未登录"):Result.build(userInfo,200,"登录成功");
    }
    @DeleteMapping("/logout")
    @Operation(summary = "退出登录")
    public Result logout(){
        return service.logout();
    }
}
